using System.Collections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using Ezio.Model;

//Service Route: Copy to 'Global.asax'
//  RouteTable.Routes.Add(new ServiceRoute("Municipios", new WebServiceHostFactory(), typeof(MunicipiosService)));
//
namespace Ezio.Service
{
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    [XmlSerializerFormat]
    public class MunicipiosService : BaseService
    {

        [WebInvoke(UriTemplate = "", Method = "POST")]
        public bool Create(Municipios Municipio)
        {
            Provider.AddToMunicipios(Municipio);
            return Provider.TrySaveChanges();
        }

        [WebInvoke(UriTemplate = "", Method = "GET")]
        public ArrayList GetAll()
        {
            return new ArrayList(Provider.Municipios.ToList());
        }

        [WebInvoke(UriTemplate = "{Id}", Method = "GET")]
        public Municipios GetById(string Id)
        {
            return Provider.Municipios.First(i => i.IdMunicipio == int.Parse(Id));
        }

        [WebInvoke(UriTemplate = "", Method = "PUT")]
        public bool Update(Municipios Municipio)
        {
            Municipios miMunicipio = Provider.Municipios.Where(t => t.IdMunicipio == Municipio.IdMunicipio).First();
            miMunicipio.Copy(Municipio);
            return Provider.TrySaveChanges();
        }

        [WebInvoke(UriTemplate = "{IdMunicipio}", Method = "DELETE")]
        public bool Delete(string IdMunicipio)
        {
            int Id = int.Parse(IdMunicipio);
            Provider.Municipios.DeleteObject(Provider.Municipios.Where(t => t.IdMunicipio == Id).First());
            return Provider.TrySaveChanges();
        }

        [WebInvoke(UriTemplate = "{IdZona}", Method = "GET")]
        public ArrayList GetByZona(int IdZona)
        {
            return new ArrayList(Provider.Municipios.Where(m => m.IdZona == IdZona).ToList());
        }
    }
}